package com.rocky.study.serial;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

public class SerialPrintDemo1 {

    static CountDownLatch CDL = new CountDownLatch(100);

    public static void main(String[] args) {
        for (int i = 100; i <= 200; i++) {
            int finalI = i;
            new Thread(() -> {
                while(true) {
                    if (finalI == 100-CDL.getCount()) {
//                        System.out.println(Thread.currentThread().getName() + "处理:" + (finalI+100));
                        System.out.println(Thread.currentThread().getName() + "处理:" + finalI);
                        CDL.countDown();
                        break;
                    }
                }
            },"t" + i).start();
        }
    }
}
